package com.example.host.controller;

import com.example.host.domain.ComputerInfo;
import com.example.host.service.ReceiveAliveMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 主控端负责接收和处理远程被控端状态信息的Controller
 */
@RestController
@Slf4j
public class ReceiveAliveMsgController {
    @Autowired
    ReceiveAliveMsgService receiveAliveMsgService;
    @PostMapping("/isAlive")
    public String isAlive(@RequestBody ComputerInfo computerInfo){
        log.info("接收到deviceClientId为" + computerInfo.getDeviceClientId() + "的被控端的状态信息：" + computerInfo);
        // 数据库中没有则插入，否则进行更新
        receiveAliveMsgService.insertOrUpdateRemoteComputerStatus(computerInfo);
        return "状态信息发送成功！";
    }
}
